/**
 * 工具脚本, 用于对比配置的文本文件中在词典数据库没有的单词, 输出到文件中
 * 注: 文本文件的格式必须是一行一个单词, 不带多余字符
 * */

var fs = require('fs');
var mongoConn = require('./store').mongoConn;

var files = [
  '../data/category/xiaoxue.txt',
  '../data/category/chuzhong.txt',
  '../data/category/gaozhong.txt'
];

var dict = [];
var diffResult = [];

for (var i = 0; i < files.length; i++) {
  var file = files[i];
  dict = dict.concat(fs.readFileSync(scaleConfig[0]).toString().split(/\s+/));
}

var count = 0;
(function diff() {
  if(count == dict.length) {
    fs.writeFileSync('diff.txt',diffResult.join('\n'));
    return;
  }
  mongoConn.find('words', {word: dict[count]}, function (err, data) {
    if(data.length == 0) {
      diffResult.push(dict[count]);
    }
    count++;
    console.log(count);
    diff();
  });
})();